/*     */ package com.zimbra.cs.ldap.unboundid;
/*     */ 
/*     */ import com.unboundid.ldap.sdk.Attribute;
/*     */ import com.unboundid.ldap.sdk.Entry;
/*     */ import com.unboundid.ldap.sdk.SearchResultEntry;
/*     */ import com.zimbra.common.util.ByteUtil;
/*     */ import com.zimbra.cs.account.AttributeManager;
/*     */ import com.zimbra.cs.ldap.LdapException;
/*     */ import com.zimbra.cs.ldap.LdapUtil;
/*     */ import com.zimbra.cs.ldap.ZAttributes;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class UBIDAttributes
/*     */   extends ZAttributes
/*     */ {
/*  35 */   private static String[] EMPTY_STRING_ARRAY = new String[0];
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   private Entry entry;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   UBIDAttributes(SearchResultEntry entry)
/*     */   {
/*  47 */     this.entry = entry;
/*     */   }
/*     */   
/*     */   UBIDAttributes(Entry entry) {
/*  51 */     this.entry = entry;
/*     */   }
/*     */   
/*     */   public void debug()
/*     */   {
/*  56 */     for (Attribute attr : this.entry.getAttributes()) {
/*  57 */       println(attr.toString());
/*     */     }
/*     */   }
/*     */   
/*     */   private String getAttrStringInternal(Attribute attr, boolean containsBinaryData)
/*     */   {
/*  63 */     if (containsBinaryData)
/*     */     {
/*     */ 
/*  66 */       byte[] bytes = attr.getValueByteArray();
/*  67 */       return ByteUtil.encodeLDAPBase64(bytes);
/*     */     }
/*     */     
/*     */ 
/*  71 */     return attr.getValue();
/*     */   }
/*     */   
/*     */   private String[] getMultiAttrStringInternal(Attribute attr, boolean containsBinaryData)
/*     */   {
/*  76 */     String[] result = new String[attr.size()];
/*     */     
/*  78 */     if (containsBinaryData) {
/*  79 */       byte[][] bytesArrays = attr.getValueByteArrays();
/*  80 */       for (int i = 0; i < bytesArrays.length; i++) {
/*  81 */         result[i] = ByteUtil.encodeLDAPBase64(bytesArrays[i]);
/*     */       }
/*     */     } else {
/*  84 */       String[] values = attr.getValues();
/*  85 */       for (int i = 0; i < values.length; i++) {
/*  86 */         result[i] = values[i];
/*     */       }
/*     */     }
/*  89 */     return result;
/*     */   }
/*     */   
/*     */   protected String getAttrString(String transferAttrName, boolean containsBinaryData)
/*     */     throws LdapException
/*     */   {
/*  95 */     Attribute attr = this.entry.getAttribute(transferAttrName);
/*     */     
/*  97 */     if (attr != null) {
/*  98 */       return getAttrStringInternal(attr, containsBinaryData);
/*     */     }
/* 100 */     return null;
/*     */   }
/*     */   
/*     */ 
/*     */   protected String[] getMultiAttrString(String transferAttrName, boolean containsBinaryData)
/*     */     throws LdapException
/*     */   {
/* 107 */     Attribute attr = this.entry.getAttribute(transferAttrName);
/*     */     
/* 109 */     if (attr != null) {
/* 110 */       return getMultiAttrStringInternal(attr, containsBinaryData);
/*     */     }
/* 112 */     return EMPTY_STRING_ARRAY;
/*     */   }
/*     */   
/*     */ 
/*     */   public Map<String, Object> getAttrs(Set<String> extraBinaryAttrs)
/*     */     throws LdapException
/*     */   {
/* 119 */     Map<String, Object> map = new HashMap();
/*     */     
/* 121 */     AttributeManager attrMgr = AttributeManager.getInst();
/*     */     
/* 123 */     for (Attribute attr : this.entry.getAttributes()) {
/* 124 */       String transferAttrName = attr.getName();
/*     */       
/* 126 */       String attrName = LdapUtil.binaryTransferAttrNameToAttrName(transferAttrName);
/*     */       
/* 128 */       boolean containsBinaryData = ((attrMgr != null) && (attrMgr.containsBinaryData(attrName))) || ((extraBinaryAttrs != null) && (extraBinaryAttrs.contains(attrName)));
/*     */       
/*     */ 
/*     */ 
/* 132 */       if (attr.size() == 1) {
/* 133 */         map.put(attrName, getAttrStringInternal(attr, containsBinaryData));
/*     */       } else {
/* 135 */         String[] result = getMultiAttrStringInternal(attr, containsBinaryData);
/* 136 */         map.put(attrName, result);
/*     */       }
/*     */     }
/* 139 */     return map;
/*     */   }
/*     */   
/*     */   public boolean hasAttribute(String attrName)
/*     */   {
/* 144 */     return this.entry.hasAttribute(attrName);
/*     */   }
/*     */   
/*     */   public boolean hasAttributeValue(String attrName, String value)
/*     */   {
/* 149 */     return this.entry.hasAttributeValue(attrName, value);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/ldap/unboundid/UBIDAttributes.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */